<?php
 /**     
  *
  * Copyright (c) 2009, Persistent Systems Limited
  *
  * Redistribution and use, with or without modification, are permitted 
  *  provided that the following  conditions are met:
  *   - Redistributions of source code must retain the above copyright notice, 
  *     this list of conditions and the following disclaimer.
  *   - Neither the name of Persistent Systems Limited nor the names of its contributors 
  *     may be used to endorse or promote products derived from this software 
  *     without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
session_start();
/**
 * File path for config.inc
 */
require_once '../Clientapp/includes/config.inc';
/**
 * File path for constants.inc
 */
require_once '../Clientapp/includes/constants.inc';
/**
 * File path for constants.inc
 */
require_once 'ServiceBus/constants.inc';
/**
 * File path for DotNetServicesEnvironment.php
 */
require_once 'DotNetServicesEnvironment.php';
/**
 * File path for MessageBufferPolicy.php
 */
require_once 'ServiceBus/MessageBufferPolicy.php';
/**
 * File path for Scope.inc.php
 */
require_once 'ACS/Scope.php';
/**
 * File path for MessageBufferClient.php
 */
require_once 'ServiceBus/MessageBufferClient.php';
/**
 * File path for HttpWebProxy.php
 */
require_once 'util/HttpWebProxy.php';
/**
 * File path for PollingService.php
 */
require_once 'PollingService.php';

$policy = new MessageBufferPolicy();

$policy->authorization = "Required";
$policy->maxMessageCount = 10;
$policy->expiresAfter = 120;
$policy->transportProtection = "None";


$scope = new Scope(CREDENTIAL_TYPE);			

$scope->setIssuerName(ISSUER_NAME);
$scope->setIssuerSecret(ISSUER_SECRET_KEY);
$scope->setServiceNamespaceDomain(SERVICE_NAMESPACE_DOMAIN);

//create an object of web proxy @see HttpWebProxy
$httpWebProxy = new HttpWebProxy(HTTP_PROXY_HOST, HTTP_PROXY_PORT);
$polingService = new PollingService();

$argv = $_GET;
if(isset($argv[1]) && $argv[1]=='stop')
{
	$polingService->stopPolling($scope,$policy,MESSAGE_BUFFER_NAME,$httpWebProxy);
}
else
{	
	$polingService->startPolling($scope,$policy,MESSAGE_BUFFER_NAME,$httpWebProxy);
}

?>